﻿GAME_NFRAME=.
# ==================================================================================
# 游戏资源构建系统 - 变量定义文件
# ==================================================================================
# 功能说明：
#   本文件定义了整个构建系统使用的所有变量、路径和配置
#   所有其他 makefile 都会引用此文件
#
# 主要内容：
#   1. 基础路径配置（源码、安装、构建路径等）
#   2. 工具路径配置（protoc、excel处理工具等）
#   3. 协议文件路径定义（proto文件输入输出）
#   4. Excel资源路径定义
#   5. 日志文件路径定义
# ==================================================================================

# ----------------------------------
# 基础路径配置
# ----------------------------------
GAME_SRC_PATH=../..

# GAME_DIR: 游戏项目目录名称
#   通过命令行参数传入，指定使用哪个游戏项目
#   默认值为空（不使用任何游戏项目）
# 
# 使用示例：
#   make GAME_DIR=LieRen                    # 使用 LieRen 项目
#   make GAME_DIR=Other                     # 使用 Other 项目
#   make GAME_DIR=MyGame                    # 使用自定义项目
#   make                                     # GAME_DIR为空，跳过game目录处理
GAME_DIR ?=

# ----------------------------------
# 版本控制配置
# ----------------------------------
# GAME_VERSION_PATCH: 版本类型标志
#   0 = 大版本（全量更新，需要重启服务器，允许生成文件发生变化）
#   1 = patch版本（热更新，不重启服务器，生成文件不能有结构性变化，否则构建失败）
# 
# 使用示例：
#   make                          # 默认为大版本（GAME_VERSION_PATCH=0）
#   make GAME_VERSION_PATCH=1      # 指定为patch版本
GAME_VERSION_PATCH ?= 0

# ----------------------------------
# 操作系统检测
# ----------------------------------
# 根据操作系统类型设置不同的工具路径和文件扩展名
ifeq ($(OS),Windows_NT)
    IS_WINDOWS = 1
else
    IS_LINUX = 1
endif

# ----------------------------------
# 游戏安装路径配置
# ----------------------------------
GAME_INSTALL_PATH=${GAME_SRC_PATH}/Install
GAME_BIN_PATH=${GAME_INSTALL_PATH}/Bin
GAME_DATA_PATH=${GAME_INSTALL_PATH}/Config/${GAME_DIR}/Data
GAME_SQL_PATH=${GAME_INSTALL_PATH}/Config/${GAME_DIR}/Sql
GAME_BUILD_PATH=${GAME_SRC_PATH}/Build/game/${GAME_DIR}/makefile
GAME_LUA_PB_PATH=${GAME_INSTALL_PATH}/LuaScript/CommonProto

# ----------------------------------
# Makefile路径配置
# ----------------------------------
# 当前目录下的各个子makefile文件
MAKEFILE_PATH=${GAME_SRC_PATH}/game/makefiles

# Excel makefile生成器
MAKE_EXCELMAKEFILE_GEN=${MAKEFILE_PATH}/excelcreate_gen.makefile
# 通用协议生成
MAKE_PROTOC_COMMON_GEN=${MAKEFILE_PATH}/protoc_common_gen.makefile
# 客户端-服务器协议生成
MAKE_PROTOC_CS_GEN=${MAKEFILE_PATH}/protoc_cs_gen.makefile
# 数据库协议生成
MAKE_PROTOC_DB_GEN=${MAKEFILE_PATH}/protoc_db_gen.makefile
# 服务器间协议生成
MAKE_PROTOC_SVR_GEN=${MAKEFILE_PATH}/protoc_svr_gen.makefile
# 存储协议生成
MAKE_PROTOC_STORE_GEN=${MAKEFILE_PATH}/protoc_store_gen.makefile
# DescStore描述文件生成
MAKE_DESCSTORE_GEN=${MAKEFILE_PATH}/descstore_gen.makefile

# ----------------------------------
# 资源Makefile路径配置
# ----------------------------------
# 由Excel自动生成的makefile存放位置
RESMETAS_MAKEFILE_PATH=${GAME_SRC_PATH}/game/${GAME_DIR}/NFLogicComm/ResStore/makefiles
# Excel生成的主makefile
MAKE_EXCEL_GEN=${RESMETAS_MAKEFILE_PATH}/excel_gen.makefile
# 资源元数据makefile
MAKE_RESMETAS_GEN=${RESMETAS_MAKEFILE_PATH}/resmetas_gen.makefile

# ----------------------------------
# Excel资源路径配置
# ----------------------------------
RESDB_EXCEL_PATH=${GAME_SRC_PATH}/game/${GAME_DIR}/Excel
RESDB_EXCELMMO_PATH=${GAME_SRC_PATH}/game/${GAME_DIR}/Excel
PROTOCGEN_FILE_PATH=${GAME_BUILD_PATH}/temp
RESDB_EXCEL_JSON=${GAME_SRC_PATH}/game/${GAME_DIR}/Excel/excel.json

# ----------------------------------
# 第三方库路径配置
# ----------------------------------
THIRD_PARTY_PATH=${GAME_SRC_PATH}/thirdparty
THIRD_PARTY_TOOLS_PATH=${THIRD_PARTY_PATH}/tools
THIRD_PARTY_INC_PATH=${THIRD_PARTY_PATH}/

# NanoPB插件配置（用于生成嵌入式友好的protobuf代码）
ifeq ($(IS_WINDOWS), 1)
    NANOPB_PLUGIN=..\..\thirdparty\nanopb\generator\protoc-gen-nanopb.bat
else
    NANOPB_PLUGIN=${THIRD_PARTY_PATH}/nanopb/generator/protoc-gen-nanopb
endif
NANOPB_PLUGIN_PROTO=${THIRD_PARTY_PATH}/nanopb/generator/proto

# ----------------------------------
# 工具路径配置
# ----------------------------------
TOOLS_PATH=${GAME_SRC_PATH}/tools
THIRD_PARTY_TOOLS_PATH=${TOOLS_PATH}

# 根据操作系统选择对应的工具可执行文件
ifeq ($(IS_WINDOWS), 1)
    PROTOC=${TOOLS_PATH}/protoc.exe
    NFEXCELPROCESS=${TOOLS_PATH}/NFExcelProcess.exe
else
    PROTOC=${TOOLS_PATH}/protoc
    NFEXCELPROCESS=${TOOLS_PATH}/NFExcelProcess
endif

FILE_COPY_EXE=${NFEXCELPROCESS}

# ----------------------------------
# 构建配置
# ----------------------------------
MAKE_SINGLE_JOB_NUM=4

# ==================================================================================
# 协议文件路径定义
# ==================================================================================
# 本节定义了所有 Protocol Buffers (protobuf) 协议文件的输入输出路径
# ==================================================================================

# ----------------------------------
# 基础协议路径
# ----------------------------------
PROTOCOL_PATH=${GAME_SRC_PATH}/src/NFrame/NFComm/Message
PROTOCOL_NANOPB_XML=${NANOPB_PLUGIN_PROTO}/nanopb.proto
PROTOCOL_FRAME_XML=$(wildcard ${PROTOCOL_PATH}/*.proto)

# ----------------------------------
# 游戏逻辑协议路径
# ----------------------------------
PROTOCOL_SVR_PATH=${GAME_SRC_PATH}/game/${GAME_DIR}/NFLogicComm/Message
PROTOCOL_SS_PATH=${GAME_SRC_PATH}/src/NFServer/NFServerComm/Message
PROTOCOL_SS_LOGIC_PATH=${PROTOCOL_SVR_PATH}/proto_svr
PROTOCOL_CS_LOGIC_PATH=${PROTOCOL_SVR_PATH}/proto_cs
COMMON_LOGIC_META_PATH=${PROTOCOL_SVR_PATH}/common
PROTOCOL_DB_META_PATH=${PROTOCOL_SVR_PATH}/proto_db

# ----------------------------------
# 资源描述文件路径
# ----------------------------------
DESC_STORE_PATH=${GAME_SRC_PATH}/game/${GAME_DIR}/NFLogicComm/ResStore/DescStore
DESC_STORE_EX_PATH=${GAME_SRC_PATH}/game/${GAME_DIR}/NFLogicComm/ResStore/DescStoreEx
RESDB_META_PATH=${GAME_SRC_PATH}/game/${GAME_DIR}/NFLogicComm/ResStore/ResMetaProto

# ----------------------------------
# 服务器间协议生成文件定义（SS: Server-Server）
# ----------------------------------
PROTOCOL_SS_LOGIC_XML=$(wildcard ${PROTOCOL_SS_LOGIC_PATH}/*.proto)
PROTOCOL_SS_LOGIC_H=$(subst $(PROTOCOL_SS_LOGIC_PATH),$(PROTOCGEN_FILE_PATH),$(PROTOCOL_SS_LOGIC_XML:.proto=.pb.h))
PROTOCOL_SS_LOGIC_CPP=$(subst $(PROTOCOL_SS_LOGIC_PATH),$(PROTOCGEN_FILE_PATH),$(PROTOCOL_SS_LOGIC_XML:.proto=.pb.cc))
PROTOCOL_SS_STRUCT_H=$(PROTOCOL_SS_LOGIC_H:.pb.h=.nanopb.h)
PROTOCOL_SS_STRUCT_CPP=$(PROTOCOL_SS_STRUCT_H:.h=.cc)

# ----------------------------------
# 客户端-服务器协议生成文件定义（CS: Client-Server）
# ----------------------------------
PROTOCOL_CS_LOGIC_XML=$(wildcard ${PROTOCOL_CS_LOGIC_PATH}/*.proto)
PROTOCOL_CS_LOGIC_H=$(subst $(PROTOCOL_CS_LOGIC_PATH),$(PROTOCGEN_FILE_PATH),$(PROTOCOL_CS_LOGIC_XML:.proto=.pb.h))
PROTOCOL_CS_LOGIC_CPP=$(subst $(PROTOCOL_CS_LOGIC_PATH),$(PROTOCGEN_FILE_PATH),$(PROTOCOL_CS_LOGIC_XML:.proto=.pb.cc))
PROTOCOL_CS_STRUCT_H=$(PROTOCOL_CS_LOGIC_H:.pb.h=.nanopb.h)
PROTOCOL_CS_STRUCT_CPP=$(PROTOCOL_CS_STRUCT_H:.h=.cc)

# ----------------------------------
# 数据库协议生成文件定义（DB: Database）
# ----------------------------------
PROTOCOL_DB_LOGIC_XML=$(wildcard ${PROTOCOL_DB_META_PATH}/*.proto)
PROTOCOL_DB_LOGIC_H=$(subst $(PROTOCOL_DB_META_PATH),$(PROTOCGEN_FILE_PATH),$(PROTOCOL_DB_LOGIC_XML:.proto=.pb.h))
PROTOCOL_DB_LOGIC_CPP=$(subst $(PROTOCOL_DB_META_PATH),$(PROTOCGEN_FILE_PATH),$(PROTOCOL_DB_LOGIC_XML:.proto=.pb.cc))
PROTOCOL_DB_STRUCT_H=$(PROTOCOL_DB_LOGIC_H:.pb.h=.nanopb.h)
PROTOCOL_DB_STRUCT_CPP=$(PROTOCOL_DB_STRUCT_H:.h=.cc)

# ----------------------------------
# 资源描述协议生成文件定义
# ----------------------------------
RESDB_DESC_XML=$(wildcard ${RESDB_META_PATH}/*.proto)
RESDB_DESC_MAKEFILE=$(wildcard ${RESDB_META_PATH}/*.makefile)
RESDB_DESC_XML2=$(subst ${RESDB_META_PATH}/,,${RESDB_DESC_XML})
RESDB_DESC_TMP_BIN=$(subst ${RESDB_META_PATH},${GAME_DATA_PATH},${RESDB_DESC_XML})
RESDB_DESC_BIN=$(subst proto,bin,${RESDB_DESC_TMP_BIN})
RESDB_DESC_BIN2=$(subst ${GAME_DATA_PATH}/,,${RESDB_DESC_TMP_BIN})
RESDB_DESC_BIN3=$(subst .proto,,${RESDB_DESC_BIN2})
RESDB_DESC_EXCEL=$(wildcard ${RESDB_EXCEL_PATH}/*.xls)

RESDB_DESC_H=$(subst $(RESDB_META_PATH),$(PROTOCGEN_FILE_PATH),$(RESDB_DESC_XML:.proto=.pb.h))
RESDB_DESC_CPP=$(RESDB_DESC_H:.h=.cc)
RESDB_DESC_STRUCT_H=$(RESDB_DESC_H:.pb.h=.nanopb.h)
RESDB_DESC_STRUCT_CPP=$(RESDB_DESC_STRUCT_H:.h=.cc)
RESDB_META_DESCRIPTOR=${PROTOCGEN_FILE_PATH}/ResMeta.proto.ds

# ----------------------------------
# 通用逻辑协议生成文件定义
# ----------------------------------
COMMON_LOGIC_DESC_XML=$(wildcard ${COMMON_LOGIC_META_PATH}/*.proto)
COMMON_LOGIC_DESC_H=$(subst $(COMMON_LOGIC_META_PATH),$(PROTOCGEN_FILE_PATH),$(COMMON_LOGIC_DESC_XML:.proto=.pb.h))
COMMON_LOGIC_DESC_CPP=$(COMMON_LOGIC_DESC_H:.h=.cc)
COMMON_LOGIC_DESC_STRUCT_H=$(COMMON_LOGIC_DESC_H:.pb.h=.nanopb.h)
COMMON_LOGIC_DESC_STRUCT_CPP=$(COMMON_LOGIC_DESC_STRUCT_H:.h=.cc)
COMMON_LOGIC_META_DESCRIPTOR=${PROTOCGEN_FILE_PATH}/CommonLogic.proto.ds
STORE_SERVER_META_DESCRIPTOR=${PROTOCGEN_FILE_PATH}/StoreServer.proto.ds
GAME_META_DESCRIPTOR=${PROTOCGEN_FILE_PATH}/${GAME_DIR}.proto.ds

# ----------------------------------
# 所有生成文件汇总
# ----------------------------------
PROTOCGEN_CPP= ${PROTOCOL_SS_LOGIC_CPP} ${RESDB_DESC_CPP} ${RESDB_DESC_STRUCT_CPP} ${PROTOCOL_CS_LOGIC_CPP} ${COMMON_LOGIC_DESC_CPP} ${COMMON_LOGIC_DESC_STRUCT_CPP}
PROTOCGEN_H=${PROTOCOL_SS_LOGIC_H} ${RESDB_DESC_H} ${RESDB_DESC_STRUCT_H} ${PROTOCOL_CS_LOGIC_H} ${COMMON_LOGIC_DESC_H} ${COMMON_LOGIC_DESC_STRUCT_H}
ALL_PROTOCGEN_FILE=${PROTOCGEN_CPP} ${PROTOCGEN_H}
ALL_PROTOC_DESCRIPTOR_FILE=
ALL_PROTOCGEN_PY=

# ----------------------------------
# 协议文件输出路径
# ----------------------------------
NEW_PROTOCGEN_FILE_PATH=${GAME_SRC_PATH}/game/${GAME_DIR}/NFLogicComm/NFServerLogicMessage
NEW_RESMETAS_FILE_PATH=${GAME_SRC_PATH}/game/${GAME_DIR}/NFLogicComm/ResStore/ResMetaS

ALL_COMMON_LOGIC_META_PATH=-I${COMMON_LOGIC_META_PATH}

# ==================================================================================
# 构建日志文件配置
# ==================================================================================
MAKE_COMPILE_LOG=${GAME_BUILD_PATH}/make_compile.log
MAKE_COMPILE_WARNING_LOG=${GAME_BUILD_PATH}/make_warning.log
MAKE_COMPILE_ERROR_LOG=${GAME_BUILD_PATH}/make_error.log
MAKE_DEPENDENT_LOG=${GAME_BUILD_PATH}/make_dependent.log
MAKE_DEPENDENT_ERROR_LOG=${GAME_BUILD_PATH}/make_dependent_error.log
MAKE_LINK_ERROR_LOG=${GAME_BUILD_PATH}/make_link_error.log

# ==================================================================================
# Excel配置文件列表
# ==================================================================================
# 从list.txt读取需要处理的Excel文件列表
EXCEL_MMO_FILES_LIST=$(shell cat ${RESDB_EXCEL_PATH}/list.txt)
EXCEL_MMO_FILES=$(foreach var, ${EXCEL_MMO_FILES_LIST}, ${RESDB_EXCEL_PATH}/$(var).xlsx)
EXCEL_MMO_PROTO_BIN_FILES=$(foreach var, ${EXCEL_MMO_FILES_LIST}, ${PROTOCGEN_FILE_PATH}/$(var).proto)
EXCEL_MMO_MAKEFILE_BIN_FILES=$(foreach var, ${EXCEL_MMO_FILES_LIST}, ${PROTOCGEN_FILE_PATH}/$(var)_gen.makefile)

RESDB_BIN_FILE=${EXCEL_MMO_PROTO_BIN_FILES} ${EXCEL_MMO_MAKEFILE_BIN_FILES}
